<?php
/**
* @package Postman
* @copyright Авторские права (C) 2009 www.yar-it.com. Все права защищены.
* @license Лицензия http://www.gnu.org/licenses/gpl-2.0.htm GNU/GPL, или help/license.php
* Postman! - свободное программное обеспечение распространяемое по условиям лицензии GNU/GPL
* Для получения информации о используемых расширениях и замечаний об авторском праве, смотрите файл copyright.php.
*/
defined( '_VALID_MOS' ) or die( '' );
// get language file for default layouts
if (file_exists(JPATH_BASE . '/administrator/components/com_postman/languages/'.$mosConfig_lang.'.php')) {
	include(JPATH_BASE . '/administrator/components/com_postman/languages/'.$mosConfig_lang.'.php');
    } else {
	include(JPATH_BASE . '/administrator/components/com_postman/languages/russian.php');
    }
	
 function com_install() {

 	 	@ini_set('max_execution_time',0);
	 	@ini_set('memory_limit','128M');


	require_once( JPATH_BASE . '/components/com_postman/defines.php');
	require_once( WPATH_ADMIN . 'config.postman.php');
	require_once( WPATH_ADMIN . 'admin.postman.html.php' );
 	require_once( WPATH_CLASS . 'class.postman.php');
	$update = new wupdate();
	$xf = new xonfig();
	$return = '';


		global $database ;


	if (!is_writable(ACA_JPATH_ROOT_NO_ADMIN . $postmanConfigFile['upload_url'])){
		@chmod(ACA_JPATH_ROOT_NO_ADMIN . $postmanConfigFile['upload_url'], 0777);
	}

	  $query[] = "UPDATE #__components
	  SET admin_menu_img='../administrator/components/com_postman/images/postman_icon.png'
	  WHERE admin_menu_link='option=com_postman'";

	  $query[] = "UPDATE #__components
	  SET admin_menu_img='../includes/js/ThemeOffice/edit.png',
	  name='"._ACA_MENU_LIST."',
	  admin_menu_alt='"._ACA_MENU_LIST."'
	  WHERE admin_menu_link='option=com_postman&act=list'";

	  $query[] = "UPDATE #__components
	  SET admin_menu_img='../includes/js/ThemeOffice/users_add.png' ,
	  name='"._ACA_MENU_SUBSCRIBERS."',
	  admin_menu_alt='"._ACA_MENU_SUBSCRIBERS."'
	  WHERE admin_menu_link='option=com_postman&act=subscribers'";

	  $query[] = "UPDATE #__components
	  SET admin_menu_img='../includes/js/ThemeOffice/messaging_inbox.png' ,
	  name='"._ACA_MENU_NEWSLETTERS."',
	  admin_menu_alt='"._ACA_MENU_NEWSLETTERS."'
	  WHERE admin_menu_link='option=com_postman&act=mailing&listype=1'";

	  $query[] = "UPDATE #__components
	  SET admin_menu_img='../includes/js/ThemeOffice/messaging_config.png' ,
	  name='"._ACA_MENU_AUTOS."',
	  admin_menu_alt='"._ACA_MENU_AUTOS."'
	  WHERE admin_menu_link='option=com_postman&act=mailing&listype=2'";

	  $query[] = "UPDATE #__components
	  SET admin_menu_img='../includes/js/ThemeOffice/query.png' ,
	   name='"._ACA_MENU_STATS."',
	   admin_menu_alt='"._ACA_MENU_STATS."'
	  WHERE admin_menu_link='option=com_postman&act=statistics'";

	  $query[] = "UPDATE #__components
	  SET admin_menu_img='../includes/js/ThemeOffice/menus.png' ,
	   name='"._ACA_MENU_CONF."',
	   admin_menu_alt='"._ACA_MENU_CONF."'
	  WHERE admin_menu_link='option=com_postman&act=configuration'";

	  $query[] = "UPDATE #__components
	  SET admin_menu_img='../includes/js/ThemeOffice/restore.png' ,
	  name='"._ACA_MENU_UPDATE."',
	  admin_menu_alt='"._ACA_MENU_UPDATE."'
	  WHERE admin_menu_link='option=com_postman&act=update'";

	  $query[] = "UPDATE #__components
	  SET admin_menu_img='../includes/js/ThemeOffice/credits.png' ,
	  name='"._ACA_MENU_ABOUT."',
	  admin_menu_alt='"._ACA_MENU_ABOUT."'
	  WHERE admin_menu_link='option=com_postman&act=about'";

 }
 function setupMaiOptions($postmanConfigFile) {

		$xf = new xonfig();
		$return =  '<br />' ._ACA_INSTALL_CONFIG .' : ';
		$config = array();
		$exist = postman::checkExisting();
		if ($exist['news1']==0) $config['news1'] = '0';
		if ($exist['news2']==0) $config['news2'] = '0';
		if ($exist['news3']==0) $config['news3'] = '0';


										//joomla 1x
			$config['emailmethod'] = $GLOBALS['mosConfig_mailer'];
			$config['sendmail_path'] = $GLOBALS['mosConfig_sendmail'];
			$config['sendmail_from'] = $GLOBALS['mosConfig_mailfrom'];
			$config['sendmail_name'] = $GLOBALS['mosConfig_fromname'];
			$config['smtp_host'] = $GLOBALS['mosConfig_smtphost'];
			$config['smtp_auth_required'] = $GLOBALS['mosConfig_smtpauth'];
			$config['smtp_username'] = $GLOBALS['mosConfig_smtpuser'];
			$config['smtp_password'] = $GLOBALS['mosConfig_smtppass'];
			$config['confirm_fromname'] = $GLOBALS['mosConfig_fromname'];
			$config['confirm_fromemail'] = $GLOBALS['mosConfig_mailfrom'];
			$config['confirm_return'] = $GLOBALS['mosConfig_mailfrom'];
	


		$config['date_update'] = postman::getNow();

		for ($index = 0; $index < $postmanConfigFile['nblist'] ; $index++) {
			$xf->insert('listname'.$index , '', 0);
			$xf->insert('listnames'.$index , '', 0);
			$xf->insert('listype'.$index , '', 0);
			$xf->insert('listshow'.$index , '', 0);
			$xf->insert('classes'.$index , '', 0);
			$xf->insert('listlogo'.$index , '', 0);
			$xf->insert('totallist'.$index , '', 0);
			$xf->insert('act_totallist'.$index , '', 0);
			$xf->insert('totalmailing'.$index , '', 0);
			$xf->insert('totalmailingsent'.$index , '', 0);
			$xf->insert('act_totalmailing'.$index , '', 0);
			$xf->insert('totalsubcribers'.$index , '', 0);
			$xf->insert('act_totalsubcribers'.$index , '', 0);
		}

		$activeList = '1';
		$config['classes1'] ='newsletter';
		$config['classes2'] ='autoresponder';
		$config['classes7'] ='autonews';

		$xf->insert('activelist' ,$activeList, 0, true);
		$xf->insert('option' ,'com_sdonkey', 0, true);

		$config['listype0'] = '1';
		$config['listname0'] = '';
		$config['listnames0'] = _ACA_MAILING_ALL;
		$config['listshow0'] = '1';
		$config['listlogo0'] = 'addedit.png';
		$config['classes0'] ='';

		$config['listype1'] = '1';
		$config['listname1'] = '_ACA_NEWSLETTER';
		$config['listnames1'] = '_ACA_MENU_NEWSLETTERS';
		$config['listshow1'] = '1';
		$config['listlogo1'] = 'inbox.png';

		$nb = explode(',', $activeList);
		$size = sizeof($nb);
		for($k = 0; $k < $size; $k ++) {
			$index = $nb[$k];
			if (class_exists($config['classes'.$index])) {
				$classConfig = new $config['classes'.$index];
				$config = array_merge($config, $classConfig->getActive());
			}
		}
		wupdate::queue2();
		if ($xf->saveConfig($config)) $return .= postman::printM('green' , _ACA_INSTALL_SUCCESS).'<br />'; else $return .='Configuration file not updated.<br />';
	 return $return;
 }
 ?>